# -*- coding: utf-8 -*-
from datetime import timedelta
from jms.dwd.oms.dwd_oms_order_dt import jms_dwd__dwd_oms_order_dt
from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dwd.tab.dwd_tab_barscan_taking_base_dt import jms_dwd__dwd_tab_barscan_taking_base_dt
from jms.dwd.dwd_elec_recycle_base_dt import jms_dwd__dwd_elec_recycle_base_dt
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dwd.tab.dwd_tab_reback_transfer_express_base_dt import jms_dwd__dwd_tab_reback_transfer_express_base_dt
from jms.dwd.tab.dwd_dependent_hi.dwd_wide_yl_rt_ssmx_bill_detail_hf_04 import jms_dwd__dwd_wide_yl_rt_ssmx_bill_detail_hf_04

jms_dm__dm_waybill_exception_detail_dt = SparkSqlOperator(
    task_id='jms_dm__dm_waybill_exception_detail_dt',
    email=['yl_bigdata@yl-scm.com','wangmenglei@jtexpress.com'],
    pool_slots=4,
    master='yarn',
    name='jms_dm__dm_waybill_exception_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_waybill_exception_detail_dt/execute.hql',
    driver_memory='10G',
    executor_memory='18G',
    executor_cores=6,
    num_executors=30,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    yarn_queue='pro',
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 40,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 180,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.sql.shuffle.partitions': 700,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          'spark.network.timeout': 900,
          'spark.core.connection.ack.wait.timeout': 300,
          'spark.sql.autoBroadcastJoinThreshold': 104857600,
          'spark.yarn.executor.memoryOverhead': '2G',
          'spark.yarn.maxAppAttempts':1,
          'spark.shuffle.file.buffer' : '64K',
          'spark.shuffle.memoryFraction': '0.8',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=5',
          'spark.shuffle.consolidateFiles':'true',
          'spark.files.maxPartitionBytes': 67108864
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
             'hive.exec.dynamic.partition.mode': 'nonstrict',
             'hive.exec.max.dynamic.partitions.pernode': 200,
             'hive.exec.max.dynamic.partitions': 200
             },
    execution_timeout=timedelta(minutes=40),
    retries=2,
    sla=timedelta(hours=5),)

jms_dm__dm_waybill_exception_detail_dt << [
    jms_dwd__dwd_oms_order_dt,
    jms_dim__dim_network_whole_massage,
    jms_dwd__dwd_tab_barscan_taking_base_dt,
    jms_dwd__dwd_elec_recycle_base_dt,
    jms_dwd__dwd_wide_yl_rt_ssmx_bill_detail_hf_04,
    jms_dwd__dwd_tab_reback_transfer_express_base_dt
]